package com.qifenqian.turbot.module.adapter.order

import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.qifenqian.turbot.R
import com.qifenqian.turbot.module.entity.response.order.OrderDetailEntity
import com.qifenqian.turbot.util.Lcat
import kotlinx.android.synthetic.main.item_dialog_dish_refund.view.*

/**
 * @author H
 * @createTime 2019/1/11 10:21
 * @description
 * @see
 * @since
 */
class OrderRefundDialogAdapter(data: List<OrderDetailEntity.OrderDishDetail>?)
    : BaseQuickAdapter<OrderDetailEntity.OrderDishDetail, BaseViewHolder>(R.layout.item_dialog_dish_refund, data) {


    var isChecked: Boolean = true
    override fun convert(helper: BaseViewHolder, item: OrderDetailEntity.OrderDishDetail) {
        val view = helper.itemView
        view.tv_item_dialog_dish_refund_name.text = item.name
        view.cb_item_dialog_dish_refund_check.setChecked(item.isChecked)
        view.cb_item_dialog_dish_refund_check.setOnClickListener {
            Lcat.a("OrderRefundDialogAdapter", isChecked)
            item.isChecked = isChecked
            view.cb_item_dialog_dish_refund_check.setChecked(isChecked)
            if (mOnCheckedChangeListener != null) {
                mOnCheckedChangeListener!!.onCheckedChanged(item)
            }
            isChecked = !isChecked
        }
    }

    fun setItemChecked(isChecked: Boolean) {
        this.isChecked = isChecked
    }

    private var mOnCheckedChangeListener: OnCheckedChangeListener? = null

    interface OnCheckedChangeListener {
        fun onCheckedChanged(item: OrderDetailEntity.OrderDishDetail)
    }

    fun setOnCheckedChangeListener(onCheckedChangeListener: OnCheckedChangeListener) {
        mOnCheckedChangeListener = onCheckedChangeListener
    }

    private fun ImageView.setChecked(isChecked: Boolean) {
        if (isChecked) {
            setImageResource(R.mipmap.ic_checked)
        } else {
            setImageResource(R.drawable.shape_circle)
        }
    }
}
